package java8._03_Lambda;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;

public class _02_方法引用 {


    public static void main(String[] args) {


        ArrayList<Integer> list = new ArrayList<>();
        list.add(5);
        list.add(3);
        list.add(28);
        list.add(210);
        list.add(23);
        for (int i = 0; i < 200; i++) {
            list.add(i);
        }


        System.out.println(list);

        List<Integer> collect = list.parallelStream()
            .sorted(Comparator.comparingInt(Integer::intValue).reversed())
            .collect(Collectors.toList());

        System.out.println(list);

        System.out.println(collect);

        TestMethod tm = new TestMethod();

        Integer xx = 1;
        methodOutObj(new Object(){
            int xx = 1;
            public double xx(int a) {
                xx += a;
                return a + xx;
            }
        }::xx);
        ObjectA objectA = new ObjectA();
        methodOutObj(objectA::xx);
        methodOutObj(objectA::xx);


        System.out.println("-------------------另外で一条，华丽の分割线----------------------");
        methodInObj(ObjectA::calc);
    }

    public static void methodOutObj(Function<Integer, Double> oper) {
        Integer a = 100;
        Double apply = oper.apply(a);
        System.out.println(apply);
    }



    public static void methodInObj(BiFunction<ObjectA, ObjectB, Double> oper) {
        ObjectA lv = new ObjectA();
        lv.xx = 100;
        ObjectB rv = new ObjectB();
        rv.xx = 200;
        Double apply = oper.apply(lv, rv);
        System.out.println(apply);
    }


    static class ObjectB {
        int xx = 1;
        public double calc(ObjectB other) {
            System.out.println("me = " + xx + " other = " + other);
            return xx + other.xx;
        }
    }


    static class ObjectA {
        int xx = 1;
        public double xx(int a) {
            xx += a;
            return a + xx;
        }
        public double calc(ObjectB other) {
            System.out.println("me = " + xx + " other = " + other);
            return xx + other.xx;
        }
    }

    static class TestMethod {
        public Double calc(Integer a, Integer b) {
            return Double.valueOf(a+1);
        }
    }
}
